<?php
/*
#####################################
# 终端修改订单前置 Le.Je.2013.03.20 #
#####################################
说明
提取终端flag=2的写入uu_order_terminal_change
*/
if (!class_exists("go_sql")){
include("/var/www/html/open/conf/le.je");
  $le=new go_sql();
  $le->connect();
}

if (!class_exists("pgconn")){
  require("/var/www/html/open/conf/pg.le.je");
  $lee = new pgconn();
  $lee->getConn();
}

$an1=array();  

$pstr="select id,src_merch,dst_merch,tid,order_state,tnum from order_info where flags=2";
$GLOBALS['lee']->pgquery($pstr);
while($row=$GLOBALS['lee']->pgFetchAssoc()){
$an1[]=$row;
}

foreach ($an1 as $v) {
//插入uu_order_terminal_change
	$str="select id from uu_order_terminal_change where ordernum='".$v['id']."' and dstatus<>2 limit 1";
	$GLOBALS['le']->query($str);
	if ($GLOBALS['le']->fetch_assoc()) continue;
	
	$str="select landid from uu_jq_ticket where id='".$v['tid']."' limit 1";
	$GLOBALS['le']->query($str);
	if (!$GLOBALS['le']->fetch_assoc()) die("无此产品或父级目录出错");
	else $lid=$GLOBALS['le']->f('landid');

	$str="select member from uu_ss_order where ordernum='".$v['id']."' limit 1";
	$GLOBALS['le']->query($str);
	$GLOBALS['le']->fetch_assoc();
	$member=$GLOBALS['le']->f('member');
	
	if ($v['order_state']!=5 && $v['order_state']!=6) die("发生致命错误，请联系技术人员");
	$stype=($v['order_state']==5)?0:1;
	$tnum=($v['order_state']==5)?$v['tnum']:0;
	//$tnum=$v['tnum'];
	$str="insert into uu_order_terminal_change set ordernum='".$v['id']."',terminal='".$v['src_merch']."',salerid='".$v['dst_merch']."',lid=$lid,tid='".$v['tid']."',stype=$stype,tnum=$tnum,stime=now(),fxid='".$member."'";
	$GLOBALS['le']->query($str);
//更新旗帜		
	$pstr="update order_info set flags=3 where flags=2 and id=".$v['id'];
	$GLOBALS['lee']->pgquery($pstr);
}

?>